package sk.tramtatiri.pages.users;

import java.util.List;

import org.apache.wicket.PageParameters;
import org.apache.wicket.ajax.AjaxSelfUpdatingTimerBehavior;
import org.apache.wicket.markup.html.WebMarkupContainer;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.form.Form;
import org.apache.wicket.markup.html.link.BookmarkablePageLink;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.markup.html.panel.Panel;
import org.apache.wicket.model.Model;
import org.apache.wicket.spring.injection.annot.SpringBean;
import org.apache.wicket.util.time.Duration;

import sk.tramtatiri.data.dao.interfaces.FoodDao;
import sk.tramtatiri.data.dataobjects.Food;

public class FoodShowPanel extends Panel{
	private static final long serialVersionUID = 3513088805277247703L;

	@SpringBean
	private FoodDao foodDao;
	private List<Food> foods;
	
	public FoodShowPanel(String id) {
		super(id);
		
		Form<?> form = new Form<Void>("formFoodShow");
		foods = foodDao.orderBy("name");
		
		ListView<Food> list = new ListView<Food>("row", foods) {

			@Override
			protected void populateItem(ListItem<Food> item) {
				final Food food = (Food) item.getModelObject();
				
				final PageParameters parameters = new PageParameters();
				parameters.put("name", food.getName());
				BookmarkablePageLink bpl = new BookmarkablePageLink("linkToFood", FoodDetailPage.class, parameters);
				bpl.add(new Label("foodName", Model.of(food.getName())));
				item.add(bpl);
				item.add(new Label("foodCalories", Model.of(food.getCalories())));
				item.add(new Label("foodSaccharides", Model.of(food.getSaccharides())));
				item.add(new Label("foodFats", Model.of(food.getFats())));
				item.add(new Label("foodProteins", Model.of(food.getProteins())));
			}
		};
		
		form.add(list);
		
		add(form);
	}
}
